//
//  CateHeaderView.m
//  悠狸
//
//  Created by dlios on 15-8-28.
//  Copyright (c) 2015年 Dung. All rights reserved.
//

#import "CateHeaderView.h"

#import "CateModel.h"
#import "UIImageView+WebCache.h"

@interface CateHeaderView()<UIScrollViewDelegate>
@property (nonatomic ,retain)NSMutableArray *array;
@property (nonatomic, retain) UIScrollView *scroll;

@end
@implementation CateHeaderView


- (void)dealloc
{
    [_array release];
    [_scroll release];
    [super dealloc];
}

- (instancetype)initWithFrame:(CGRect)frame array:(NSArray *)array
{
    self = [super initWithFrame:frame];
    if (self) {
        self.array = [NSMutableArray array];
        [self.array addObjectsFromArray:array];
              [self createScroll];
      
    }
    return self;
}
- (void)createScroll
{
    
    UILabel *lable = [[[UILabel alloc ]initWithFrame:CGRectMake(0, 0, self.frame.size.width, 40*OffHeight)]autorelease];
    lable.backgroundColor = [UIColor redColor];
    [self addSubview:lable];
    
    self.scroll = [[[UIScrollView alloc] initWithFrame:CGRectMake(0, 40*OffHeight, self.frame.size.width, 110*OffHeight)] autorelease];
    _scroll.contentSize = CGSizeMake(_scroll.frame.size.width  *5*OffWidth, 0);
    _scroll.contentOffset = CGPointMake(0, 0);
    _scroll.backgroundColor= [UIColor yellowColor];

    
    _scroll.delegate =self;
    _scroll.bounces = NO;
   
//    _scroll.showsHorizontalScrollIndicator = NO;
    [self addSubview:_scroll];
    
    for (int i = 0; i < self.array.count; i++) {
        
       
        CateModel *cate = [self.array objectAtIndex:i];
        
        NSString *url = cate.banner_image_url;
        
        cate.banner_image_url = url;
    
        UIImageView *image = [[UIImageView alloc] initWithFrame:CGRectMake((i * 160+ 20)*OffWidth, 10*OffHeight, 140*OffWidth, 90*OffHeight)];
        [image sd_setImageWithURL:[NSURL URLWithString:cate.banner_image_url] placeholderImage:[UIImage imageNamed:@"000.jpg"]];
        [self.scroll addSubview:image];
        [image release];
    }
    
}
@end
